package com.linkhouse.mq;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component                                                  //消费者组
@RocketMQMessageListener(topic = "Phone",consumerGroup = "ddsc_2109")
public class SendMassageMQ implements RocketMQListener<String>{

    @Resource
    private Client client;

    @Override
    public void onMessage(String ss) {
        String s = RandomStringUtils.randomNumeric(4);
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(ss)
                .setSignName("东科创想")
                .setTemplateCode("SMS_162522027")
                .setTemplateParam("{\"sms_code\":\""+s+"\"}");
        // 复制代码运行请自行打印 API 的返回值
        try {
            client.sendSms(sendSmsRequest);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
